<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateGoodsTable extends Migration
{
    /**
     * 创建商品表
     *
     * @return void
     */
    public function up()
    {
        Schema::create('goods', function (Blueprint $table) {
            //表属性
            $table->engine = 'InnoDB';
            $table->charset = 'utf8';
            $table->collation = 'utf8_general_ci';
            //表字段
            $table->increments('id');
            $table->string('sn',45)->comment('商品编号');
            $table->string('name',45)->comment('商品名称');
            $table->integer('cate_id')->comment('商品分类');
            $table->integer('saled_num')->default(0)->comment('已售数量');

            $table->string('description',45)->nullable()->comment('产品描述');
            $table->string('thumb',255)->comment('商品缩略图即展示图');
            $table->text('content')->nullable()->comment('商品详情');
            $table->string('picture',255)->comment('商品大图');

            $table->decimal('price',10,2)->comment('商品价格');
            $table->integer('stock')->comment('商品库存');
            $table->tinyInteger('on_sale')->defalut(1)->comment('是否上架,1:上架,0:下架，默认1');
            $table->tinyInteger('is_recommented')->defalut(0)->comment('是否做为推荐,1:推荐,0:不推荐,默认0');

            $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'))->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
            $table->timestamp('deleted_at')->nullable()->comment('删除时间');
            //创建索引
            $table->unique('name');
            $table->unique('sn');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('goods');
    }
}
